<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('易达电表数据管理')" />
    <th:block th:include="include :: bootstrap-select-css" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>炉号：</label>
                                <input type="text" name="furnaceNo" placeholder="请输入炉号"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status">
                                    <option value="">所有</option>
                                    <option value="1">正常</option>
                                    <option value="0">异常</option>
                                </select>
                            </li>
                            <li>
                                <label>开始日期：</label>
                                <input type="text" class="time-input" id="startDate" placeholder="开始日期" name="startDate"/>
                            </li>
                            <li>
                                <label>结束日期：</label>
                                <input type="text" class="time-input" id="endDate" placeholder="结束日期" name="endDate"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="resetForm()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:ydmeterdata:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-info" onclick="openStatistics()" shiro:hasPermission="system:ydmeterdata:statistics">
                    <i class="fa fa-bar-chart"></i> 统计
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:ydmeterdata:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:ydmeterdata:remove')}]];
        var prefix = ctx + "system/ydmeterdata";
    
        // 自定义重置函数
        function resetForm() {
            // 不调用系统默认的重置方法，而是直接清空表单字段
            $("#formId")[0].reset();
            
            // 然后重新设置当天日期
            var today = new Date();
            var year = today.getFullYear();
            var month = (today.getMonth() + 1).toString().padStart(2, '0');
            var day = today.getDate().toString().padStart(2, '0');
            var dateStr = year + "-" + month + "-" + day;
            $("#startDate").val(dateStr);
            $("#endDate").val(dateStr);
            
            // 重新搜索以更新表格数据
            $.table.search();
        }
    
        $(function() {
            // 设置当天日期为默认值
            var today = new Date();
            var year = today.getFullYear();
            var month = (today.getMonth() + 1).toString().padStart(2, '0');
            var day = today.getDate().toString().padStart(2, '0');
            var dateStr = year + "-" + month + "-" + day;
            $("#startDate").val(dateStr);
            $("#endDate").val(dateStr);
            
            // 日期选择器由框架自动初始化
            
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "易达电表数据",
                queryParams: function(params) {
                    var search = {};
                    $.each($("#formId").serializeArray(), function(i, field) {
                        search[field.name] = field.value;
                    });
                    search.pageSize = params.limit;
                    search.pageNum = params.offset / params.limit + 1;
                    search.orderByColumn = params.sort;
                    search.isAsc = params.order;
                    return search;
                },
                columns: [{
                    field: 'id',
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'collectTime',
                    title: '采集时间'
                },
                {
                    field: 'furnaceNo',
                    title: '炉号'
                },
                {
                    field: 'furnaceEnergy',
                    title: '单炉电量(kWh)',
                    formatter: function(value, row, index) {
                        return (value && !isNaN(value)) ? parseFloat(value).toFixed(2) : '-';
                    }
                },
               
                {
                    field: 'activePower',
                    title: '有功功率(kW)',
                    formatter: function(value, row, index) {
                        return (value && !isNaN(value)) ? parseFloat(value).toFixed(2) : '-';
                    }
                } ,
                {
                    field: 'dcCurrent',
                    title: '直流电流(kA)',
                    formatter: function(value, row, index) {
                        return (value && !isNaN(value)) ? parseFloat(value).toFixed(2) : '-';
                    }
                },
                {
                    field: 'dcVoltage',
                    title: '直流电压(V)',
                    formatter: function(value, row, index) {
                        return (value && !isNaN(value)) ? parseFloat(value).toFixed(2) : '-';
                    }
                },
                {
                    field: 'dcResistance',
                    title: '直流炉阻(mΩ)',
                    formatter: function(value, row, index) {
                        return (value && !isNaN(value)) ? parseFloat(value).toFixed(2) : '-';
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        if (value == 1) {
                            return '<span class="badge badge-success">正常</span>';
                        } else {
                            return '<span class="badge badge-danger">异常</span>';
                        }
                    }
                },
                {
                    field: 'deviceId',
                    title: '设备ID',
                    visible: false
                }]
            };
            $.table.init(options);
        });

        // 打开统计页面
        function openStatistics() {
            var url = prefix + "/statistics";
            $.modal.openTab("数据统计", url);
        }
    </script>
</body>
</html>